class MainController < ApplicationController
  def gmap
    @marks= [
      {:lat=>13.862222, :lng=>100.513333, :title=>'เมือง'},
      {:lat=>13.805, :lng=>100.47277, :title=>'บางกรวย'},
      {:lat=>13.876667, :lng=>100.403889, :title=>'บางใหญ่'}
    ]
  end
  def test_soap
    require 'soap/wsdlDriver'
    XSD::Charset.encoding = 'UTF8'
    wsdl = "http://localhost:3999/test_ws/wsdl"
    driver = SOAP::WSDLDriverFactory.
      new(wsdl).create_rpc_driver
    @result = driver.dogreeting('songrit')
    render :text => @result
  end
  def ptt
    require 'soap/wsdlDriver'
    XSD::Charset.encoding = 'UTF8'
    wsdl = "http://www.pttplc.com/pttinfo.asmx?wsdl"
    driver = SOAP::WSDLDriverFactory.new(wsdl).create_rpc_driver
    @result = driver.CurrentOilPrice(:Language=>'EN')
    @h= Hash.from_xml @result['CurrentOilPriceResult']
  end
  def twitter
    require "open-uri"
    @result= open("http://twitter.com/users/show/bob.xml")
    @h = Hash.from_xml(@result)
  end
  def index
    render :text => "hello"
  end
  def yahoo
    require "open-uri"
    query = CGI.escape("gdi")
    yahookey = "songrit_gdi"
    url = "http://api.search.yahoo.com/" +
      "WebSearchService/V1/webSearch?" +
      "appid=#{yahookey}&query=#{query}" +
      "&results=3&start=1"
    result = open(url)
    @doc = REXML::Document.new result
    render :text => url
  end
  def fed
    require "open-uri"
    url= "http://www.fedspending.org/fpds/fpds.php?datype=X&detail=-1&state=CA"
    @result= open(url)
    @h = Hash.from_xml(@result)
  end

  def rexml
    require "rexml/document"
    file= File.new("rexml_lab.xml")
    @doc = REXML::Document.new file
  end

  def statxml
    require "rexml/document"
    require "open-uri"
    result= open("http://ws.nic.go.th/wservice/public/4264")
    doc = REXML::Document.new result
    doc.elements.each("//Value") do |entry|
      @word = entry.attributes['value'] if entry.attributes['concept']=='UNIT'
    end
    render :text => @word
  end
#  def test_app
#    render :text => "text to render..."
#  end
#  def test_soap
#    require 'soap/wsdlDriver'
#    XSD::Charset.encoding = 'UTF8'
#    wsdl = "http://localhost:3999/test_ws/wsdl"
#    driver =
#        SOAP::WSDLDriverFactory.new(wsdl).create_rpc_driver
#    @result = driver.dogreeting('songrit')
#    render :text => @result
#  end
end
